package com.wuseguang.springcloud.controller;


import com.wuseguang.springcloud.Classcardservice.ClassCardService;
import com.wuseguang.springcloud.Filter.RequestParameterWrapper;
import com.wuseguang.springcloud.service.TeachingClassesService;
import com.wuseguang.springcloud.util.CodeUtil;
import com.wuseguang.springcloud.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @描述 首页-->我的管理班级和任教班级
 * @创建人 zm
 * @创建时间 2019/11/27
 */
@RestController
@RequestMapping("/teachingclasses")
public class TeachingClassesController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private TeachingClassesService classesService;

    //推送接口
    @Autowired
    private ClassCardService classCardService;

    /**
     * 返回我是班主任的班级和我任教的班级 全部列表
     *
     * @return
     */
    @RequestMapping("/findAll")
    public Result headTeacHerandTeaching(RequestParameterWrapper request) {
        String admin = request.getParam("admin");
        String schoolId = request.getParam("schoolId");
        String teacherId = request.getParam("teacherId");
        logger.info("admin={},schoolId={},teacherId={}", admin, schoolId, teacherId);
        return new Result(classesService.findAll(schoolId, teacherId));
    }


    /**
     * @描述 查询班级信息
     * @创建人 zm
     * @创建时间 2019/12/15
     */
    @RequestMapping("/onefindClass")
    public Result onefindClass(RequestParameterWrapper request, @RequestParam("classid") String classid) {
        String schoolId = request.getParam("schoolId");
        logger.info("schoolId={}", schoolId);
        return new Result(classesService.onefindClass(schoolId, classid));
    }

    /**
     * @描述 修改班级信息
     * @创建人 zm
     * @创建时间 2019/12/15
     */
    @RequestMapping("/updateClass")
    public Result updateClass(RequestParameterWrapper request, @RequestParam("classid") String classid,
                              @RequestParam(value = "classicon", required = false) String classicon,
                              @RequestParam("classname") String classname,
                              @RequestParam(value = "slogan", required = false) String slogan) {
        String schoolId = request.getParam("schoolId");
        logger.info("schoolId={}", schoolId);
        int i = classesService.updateClass(schoolId, classicon, classname, slogan, classid);
        if (i > 0) {
            classCardService.classesAndCards(classid);
            return new Result();
        }
        return new Result(CodeUtil.MODIFICATION_FAILED);
    }
}
